from app.api.api_base import BaseResource
from app.services.service_user import service_user
from flask import abort, request
from .condition import check_user_login_unique_id_exist

class ApiEmailSend(BaseResource):
	"""发送邮件"""
	def __init__(self):
		super(ApiEmailSend, self).__init__()

	def post(self):
		args = [
			dict(name="email", type=str, required=True, help="邮箱错误"),
			dict(name="password", type=str, required=True, help="密码错误")
		]
		self.add_arguments(args)
		return service_user.user_register(self.get_args())

class ApiLogin(BaseResource):
	"""登录"""
	def __init__(self):
		super(ApiLogin, self).__init__()

	def get(self):
		args = [
			dict(name="unique_id", type=str, required=True, help="用户名错误"),
			dict(name="password", type=str, required=True, help="密码错误")
		]

		self.condition = {
			"unique_id": check_user_login_unique_id_exist
		}
		self.add_arguments(args)
		return service_user.user_login(self.get_args())
